<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>用户</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">
    <link rel="stylesheet"  href="../../../css/zTreeStyle/zTreeStyle.css">
    <script src="../../../layui/layui.js"></script>
    <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
    <script type="text/javascript" src="../../../js/url.js"></script>
</head>
<style type="text/css">
 body{
  height: 100%;
  width: 100%;
}
.ztree {
    margin: 0;
    padding: 5px;
    color: #333;
}
.hidden{
	display:none;
}
.controls input[type='text']{border: 1px solid #e6e6e6;height: 26px}
</style>

<body >
<!-- 内容主体区域 -->
<div class="layui-row layui-col-space5">
    <div class="layui-col-md5 border">
        <div class="layui-fluid layui-form">
            <div class="layui-form-item">
                <div class="layui-input-inline " style=" width: 638px;">
                    <button class="layui-btn layui-btn-primary updateRolePower">菜单资源配置</button>
                    <!--      <button class="layui-btn">默认按钮</button>
                          <button class="layui-btn layui-btn-normal">百搭按钮</button>-->
                    <button class="layui-btn layui-btn-primary writeIn">生成省市区文件</button>

                    <button class="layui-btn layui-btn-primary exports"  >导出美容院信息</button>

                    <button class="layui-btn layui-btn-primary exports2">导出salon信息</button>


                    <input  id="tel" placeholder="请输入手机"  value="" class="layui-input">
                    <button class="layui-btn layui-btn-primary deleteStuff">删除家人</button>

                    <button class="layui-btn layui-btn-primary deleteMember">删除顾客</button>
                    <!--<button class="layui-btn layui-btn-primary sendMessage">发送短信验证码</button>-->
                </div>

            </div>
        </div>
        <div id="treeDiv" >
            <div class="layui-form-item ">
                <div class="layui-inline">
                    <div class="tree tree-selectable"><ul id="tree" class="ztree"></ul></div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<input name="listMenuId" id="listMenuId"  type="hidden" value="" class="layui-input">

</body>
<script type="text/javascript">

    layui.use(['form','laydate','layer','table','laypage','util'],function() {

        var $ = layui.$;


        $(".sendMessage").click(function () {

           var tel= $("#tel").val();
            $.ajax({
                type: 'GET',
                url: '/hy/basic/salon/testSendMessage',
                data:{"tel":tel},
                contentType: "application/json",
                success: function (data) {
                    layer.alert('发送成功');

                },
                error: function (data) {
                    layer.alert("操作失败");
                    console.log(data);
                }
            })

        })




        $(".deleteStuff").click(function () {

            var tel= $("#tel").val();
            $.ajax({
                type: 'GET',
                url: '/hy/basic/statistics/deleteStuffForTel',
                data:{"tel":tel},
                contentType: "application/json",
                success: function (data) {
                    layer.alert('删除成功');

                },
                error: function (data) {
                    layer.alert("操作失败");
                    console.log(data);
                }
            })

        })

        $(".deleteMember").click(function () {

            var tel= $("#tel").val();
            $.ajax({
                type: 'GET',
                url: '/hy/basic/statistics/deleteMemberForTel',
                data:{"tel":tel},
                contentType: "application/json",
                success: function (data) {
                    layer.alert('删除成功');

                },
                error: function (data) {
                    layer.alert("操作失败");
                    console.log(data);
                }
            })

        })


        $(".writeIn").click(function () {
            $.ajax({
                type: 'GET',
                url: '/hy/basic/salon/writeIn',
                contentType: "application/json",
                success: function (data) {
                    layer.alert('操作成功,省市区文件已更至最新');

                    // window.parent.location.reload(); //刷新父页面
                    // var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    //parent.layer.close(index);  // 关闭layer

                },
                error: function (data) {
                    layer.alert("操作失败");
                    console.log(data);
                }
            })

        })

        $(".exports").click(function () {
            $.ajax({
                url:"/hy/basic/salon/exportSalon",
                type:"post",
                data:{type:"1"},
                dataType:"json",
                success:function(data){

                    console.log(data.data.data.dataUrl);
                    console.log("+++"+JSON.stringify(data));
                    if(data.data.data.respCode == "0000"){

                        window.location.href = ctx+"/orderData/"+data.data.data.dataUrl;
                    }else{
                        alert(data.data.data.respDesc)
                    }
                },
                error:function(){
                    alert("导出异常");
                }
            });

        })

        $(".exports2").click(function () {
            $.ajax({
                url:"/hy/basic/salon/exportSalon",
                type:"post",
                data:{type:"0"},
                dataType:"json",
                success:function(data){

                    console.log(data.data.data.dataUrl);
                    console.log("+++"+JSON.stringify(data));
                    if(data.data.data.respCode == "0000"){

                        window.location.href = ctx+"/orderData/"+data.data.data.dataUrl;
                    }else{
                        alert(data.data.data.respDesc)
                    }
                },
                error:function(){
                    alert("导出异常");
                }
            });

        })


        //导出报表
        function exports(){
            $.ajax({
                url:"/hy/basic/salon/exportSalon",
                type:"post",
                dataType:"json",
                success:function(data){
                    if(data.data.respCode == "0000"){

                        window.location.href = ctx+"/orderData/"+data.data.dataUrl
                    }else{
                        alert(data.data.respDesc)
                    }
                },
                error:function(){
                    alert("导出异常");
                }
            });

        }


    })

    $(function(){
    
   /*  $(".controls :radio").click(function(){
	 }); */






    //新增菜单按钮
    $(".addNewResource").click(function() {
    	$('.menuName2').addClass("hidden");
    	$('.orderNum2').addClass("hidden");
    	
    	
    	$('.menuName').removeClass("hidden");
    	$('.orderNum').removeClass("hidden");
    	$('.iconClass').removeClass("hidden");
        $("#myModal,.page-mask").addClass("in")
        $('#parentId').val(0);
        $('#hasChildren').val(1);
        
    });
    $(".closeNews").click(function(){
     	$("#myModal,.page-mask").removeClass("in")
    });
    
    $(".closeNewsChildren").click(function(){
     	$('#myModal,.page-mask').removeClass('in');
    });


    //保存新子订单
    $(".saveInfo").click(function(){
    	var formdata ={};
		var menuName = $('#menuName').val();
		var menuLvl = $('input[name="menuLvl"]:checked').val();
		var menuType = $('input[name="menuType"]:checked').val();
		var menuUrl = $("#menuUrl").val();
		var id = $('#menuId').val();

		formdata.id= id;
		$.ajax({
			type: 'post',
			dataType: 'json', 
			data:{
				"menu":JSON.stringify(formdata)
			},
			url:'${basePath}menu/addMenu',
			success:function(res){
				var data = JSON.parse(res);
				if(data.state=='success'){
					$('#myModal,.page-mask').removeClass('in');
					var data = data.treeList;
					console.log(JSON.stringify(data));
			        var t = $("#tree");
			        t = $.fn.zTree.init(t, setting, data);
			        demoIframe = $("#testIframe");
			        demoIframe.bind("load", loadReady);
			        var zTree = $.fn.zTree.getZTreeObj("tree");
				}
				//alert(data);
			}
		})
    })
});

var setting = {
    expandSpeed : "slow",
    // check: {
    //     enable: true
    // },
    view: {
        addHoverDom: addResource,
        removeHoverDom: removeHoverDom,
        dblClickExpand: false,
        showLine: true,
        selectedMulti: false
    },
    /* edit: {
       enable: true,
       editNameSelectAll: true,
       showRemoveBtn: removeResource,
       showRenameBtn: renameResource
  }, */
    data: {
        simpleData: {
            enable:true,
            idKey: "uuid",
            pIdKey: "resourceParent",
            rootPId: "0"
        }
    },
    callback: {
        beforeClick: function(treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("tree");
            if (treeNode.isParent) {
                zTree.expandNode(treeNode);
                return false;
            } else {
                demoIframe.attr("src",treeNode.file + ".html");
                return true;
            }
        }
    }
};
var newCount = 1;
function addResource(treeId, treeNode) {
	
    var sObj = $("#" + treeNode.tId + "_span");
    if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
        + "' title='add node' onfocus='this.blur();'></span>";
        
    var editStr = "<span class='button edit' id='eidtBtn_" + treeNode.tId
        + "' title='edit node' onfocus='this.blur();'></span>";
    sObj.after(editStr);
    sObj.after(addStr);
    var btn = $("#addBtn_"+treeNode.tId);
    
    var eidt =  $("#eidtBtn_"+treeNode.tId);
    if (btn) btn.bind("click", function(){
        var parentId = treeNode.id;
        $('#parentId').val(parentId);
         $('#menuName').val('');
    	$('#orderNum').val('');
    	$('#menuUrl').val('');
    	$('#menuDesc').val('');
    	$('#menuId').val('');
    	$('#hasChildren').val(0);
        $('.menuName').addClass("hidden");
    	$('.orderNum').addClass("hidden");
    	$('.iconClass').addClass("hidden");
    	$('.menuName2').removeClass("hidden");
    	$('.orderNum2').removeClass("hidden");
        $('#myModal,.page-mask').addClass('in');
    });

}
function removeHoverDom(treeId, treeNode) {
    $("#addBtn_"+treeNode.tId).unbind().remove();
    $("#eidtBtn_"+treeNode.tId).unbind().remove();
};

var removeResource = function () {

}

var renameResource = function () {

}
$(document).ready(function(){
		// var data =${treeList};
		// console.log(JSON.stringify(data));
        // var t = $("#tree");
        // t = $.fn.zTree.init(t, setting, data);
        // demoIframe = $("#testIframe");
        // demoIframe.bind("load", loadReady);
        // var zTree = $.fn.zTree.getZTreeObj("tree");
});

function loadReady() {
    var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
        htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
        maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
        h = demoIframe.height() >= maxH ? minH:maxH ;
    if (h < 530) h = 530;
    demoIframe.height(h);
}

  </script>